package com.gzx.bi.modular.attend.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.gzx.bi.modular.attend.bo.GzxProjectAttendanceEditVo;
import com.gzx.bi.modular.attend.entity.GzxProjectAttendance;
import com.gzx.bi.modular.attend.mapper.GzxProjectAttendanceMapper;
import com.gzx.bi.modular.attend.service.GzxProjectAttendanceService;
import com.gzx.bi.modular.attend.vo.GzxProjectAttendanceVo;
import com.gzx.bi.modular.project.vo.GzxProjectDebtVo;
import com.gzx.tjzy.feign.GzxProjectFeign;
import com.gzx.tjzy.feign.resp.project.GzxProjectRespDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 出勤信息
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class GzxProjectAttendanceServiceImpl implements GzxProjectAttendanceService {

    private final GzxProjectFeign projectFeign;

    private final GzxProjectAttendanceMapper attendanceMapper;

    /**
     * 获取当天某个项目的出勤信息
     */
    @Override
    public List<GzxProjectAttendance> getCurrentAttendance(List<GzxProjectDebtVo> projectDebtList) {
        return attendanceMapper.getCurrentAttendance(projectDebtList);
    }

    /**
     * 修改项目的出勤率
     */
    @DS("bi")
    @Override
    public void edit(GzxProjectAttendanceEditVo param) {
        GzxProjectAttendance entity = new GzxProjectAttendance();
        entity.setId(param.getId());
        entity.setAttendUser(param.getAttendUser());
        attendanceMapper.updateById(entity);
    }

    //获取出勤信息
    @DS("bi")
    @Override
    public List<GzxProjectAttendanceVo> listCurrentAttendance() {
        //获取所有有有案件的项目
        List<GzxProjectRespDto> rsp = projectFeign.listCaseProject();
        log.info("出勤信息：{}", rsp);
        //初始化当天各项目的考勤
        if (rsp != null) {
            attendanceMapper.insertOnDuplicate(rsp);
        }
        return attendanceMapper.listCurrentAttendance();
    }

}
